#ifndef _JSON_VALUE_H_
#define _JSON_VALUE_H_
#include <map>
#include <string>
#include <vector>

struct json_object;

namespace Json
{	

	enum ValueType
	{
		nullValue = 0, ///< 'null' value
		booleanValue,  ///< bool value
		realValue,     ///< double value
		intValue,      ///< signed integer value
		objectValue,    ///< object value (collection of name/value pairs).
		arrayValue,    ///< array value (ordered list)
		stringValue,   ///< UTF-8 string value
	};

	class Value;
	typedef std::map<std::string,Value*>	ParamTable;
	typedef std::vector<Value*>				ValueArray;

	class ValueIterator
	{
	public:
		ValueIterator( const ParamTable& table, ParamTable::iterator it );
	public:
		ValueIterator&					operator++();
		ValueIterator					operator++(int);
		ValueIterator&					operator--();
		ValueIterator					operator--(int);
		bool							operator==(const ValueIterator& v);
		bool							operator!=(const ValueIterator& v);
		Value&							operator*();

	private:
		const ParamTable&				m_paramTable;
		ParamTable::iterator			m_it;

	};

	class Value
	{
	public:
		typedef class ValueIterator				iterator;
	public:
		Value();
		explicit Value( const Value& );
		~Value();
	public:

		bool init( const char * jsonStr );
		bool init( json_object * json );

		iterator begin();
		iterator end();

		void				clear();
		ValueType			type();
		int					size();

		bool				has( const std::string& key );
		Value&				operator[]( const std::string& key );
		const Value&		operator[]( const std::string& key )const;
		Value&				operator[]( int index );
		Value&				operator=( const Value & v ){};


		int					asInt();
		bool				asBool();
		std::string			asString();

	private:

		json_object *	m_jsonObject;
		bool			m_isRoot;
		
		ParamTable		m_paramTable;
		ValueArray		m_valueArray;

	};
};

#endif